package com.yi.wood.web.ctrl;

import com.yi.wood.web.socket.SystemWebSocket;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author moyi
 * @since 1.0
 * 2019-01-23
 */
@RestController
@RequestMapping("/sys")
public class SysCtrl extends BaseCtrl {

    @Resource
    private SystemWebSocket systemWebSocket;

    @RequestMapping(value = "info",method = RequestMethod.GET)
    public Object info(){
        Map<String,Object> resultMap = new HashMap<>(8);
        Runtime rt = Runtime.getRuntime();
        int byteToMb = 1024 * 1024;
        // 虚拟机级内存情况查询
        long vmTotal = rt.totalMemory() / byteToMb;
        long vmFree = rt.freeMemory() / byteToMb;
        float m = ((vmTotal - vmFree)/(float)vmTotal) *100;
        resultMap.put("m",(int)m);
        resultMap.put("t",vmTotal);
        resultMap.put("u", vmTotal-vmFree);
        systemWebSocket.sendGroup("hello");
        return success(resultMap);
    }
}
